package com.zyh.homework.test5;

import java.io.*;

/**
 * @Author zyh
 * @Date 2024/8/6 19:00
 * @Description 3.	分别使用文件流和缓冲流复制一个长度大于100MB的视频文件，并观察效率的差异。
 */

public class Test5 {
    public static final String FILE_PATH="D:\\Code\\IDEA\\idea_projects\\JavaSE-plus\\day10-code\\src\\com\\zyh\\homework\\test5\\resources\\092-QQ斗地主初级版.avi";
    public static final String FILE_PATH1="D:\\Code\\IDEA\\idea_projects\\JavaSE-plus\\day10-code\\src\\com\\zyh\\homework\\test5\\resources\\a\\QQ斗地主初级版.avi";

    public static void main(String[] args) throws IOException {
        //文件流
        long time1 = System.currentTimeMillis();
        FileInputStream fis = new FileInputStream(FILE_PATH);
        FileOutputStream fos = new FileOutputStream(FILE_PATH1);
        byte[] car=new byte[1024];
        int len=-1;
        while ((len=fis.read(car))!=-1){
            fos.write(car,0,len);
        }
        long time2 = System.currentTimeMillis();
        System.out.println("文件流总共花费时间："+(time2-time1));
        //缓冲流
        long time3 = System.currentTimeMillis();
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream(FILE_PATH));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(FILE_PATH1));
        byte[] car1=new byte[1024];
        int len1=-1;
        while ((len1=bis.read(car))!=-1){
            bos.write(car,0,len1);
        }
        long time4 = System.currentTimeMillis();
        System.out.println("缓冲流总共花费时间："+(time4-time3));
    }
}
